﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;

using QLTTAN.DTO;
namespace QLTTAN.DAL
{
    public class GiaoVienDAL
    {
        ConnectionData conn;

        public DataRow GiaoVien_GetInfo(GiaoVienDTO GV_DTO)
        {
            conn = new ConnectionData();

            int Nparameter = 1;
            string[] name = new string[Nparameter];
            object[] value = new object[Nparameter];

            name[0] = "MaGV";
            value[0] = GV_DTO.MaGV;

            return conn.GetData("GIAOVIEN_GETINFO", name, value, Nparameter).Rows[0];
        }

        public DataTable GiaoVien_Load()
        {
            conn = new ConnectionData();
            return conn.GetData("GIAOVIEN_LOAD");
        }

        public int GiaoVien_Insert(GiaoVienDTO GV_DTO)
        {
            conn = new ConnectionData();

            int Nparameter = 8;
            string[] name = new string[Nparameter];
            object[] value = new object[Nparameter];

            name[0] = "TenGV";
            value[0] = GV_DTO.TenGV;
            name[1] = "NgaySinh";
            value[1] = GV_DTO.NgaySinh;
            name[2] = "GioiTinh";
            value[2] = GV_DTO.GioiTinh;
            name[3] = "Email";
            value[3] = GV_DTO.Email;
            name[4] = "DiaChi";
            value[4] = GV_DTO.DiaChi;
            name[5] = "DienThoai";
            value[5] = GV_DTO.DienThoai;
            name[6] = "CMND";
            value[6] = GV_DTO.CMND;
            name[7] = "BangCap";
            value[7] = GV_DTO.BangCap;
            
            return conn.UpdateData("GIAOVIEN_INSERT", name, value, Nparameter);
        }

        public int GiaoVien_Update(GiaoVienDTO GV_DTO)
        {
            conn = new ConnectionData();

            int Nparameter = 9;
            string[] name = new string[Nparameter];
            object[] value = new object[Nparameter];

            name[0] = "MaGV";
            value[0] = GV_DTO.MaGV;
            name[1] = "TenGV";
            value[1] = GV_DTO.TenGV;
            name[2] = "NgaySinh";
            value[2] = GV_DTO.NgaySinh;
            name[3] = "GioiTinh";
            value[3] = GV_DTO.GioiTinh;
            name[4] = "Email";
            value[4] = GV_DTO.Email;
            name[5] = "DiaChi";
            value[5] = GV_DTO.DiaChi;
            name[6] = "DienThoai";
            value[6] = GV_DTO.DienThoai;
            name[7] = "CMND";
            value[7] = GV_DTO.CMND;
            name[8] = "BangCap";
            value[8] = GV_DTO.BangCap;

            return conn.UpdateData("GIAOVIEN_UPDATE", name, value, Nparameter);
        }

        public int GiaoVien_Delete(GiaoVienDTO GV_DTO)
        {
            conn = new ConnectionData();

            int Nparameter = 1;
            string[] name = new string[Nparameter];
            object[] value = new object[Nparameter];

            name[0] = "MaGV";
            value[0] = GV_DTO.MaGV;

            return conn.UpdateData("GIAOVIEN_DELETE", name, value, Nparameter);
        }
    }
}
